/**
 *  MALON !Oliki! diagrafi.
 */

package GUI;

import java.awt.Point;
import javax.swing.*;
 
public class sqrGUI extends JLabel{
    /**
     * @param movable An to Piece ine kinisimo i ohi ( apo to mouse ).
     * @param color to hroma tou Piece ( 'W' / 'B').
     * @param x I X sindetagmni apo tis 2D diastasis tou [x][y].
     * @param y I Y sindetagmni apo tis 2D diastasis tou [x][y].
     */
    private boolean movable;
    private char color;
    private Point pos;
    
    /**
     * Kani Constrac ena Piece.
     * ta X=Y= -1; ehon to skopo na min simbiptoun se kamia periptosi me iparhouses thesis tou Board afou den boroume na ehoume arhitikes times se autes.
     */
    public sqrGUI(){
        movable = false;
        color = 'N';
        pos.x = -1;
        pos.y = -1;
    }
    
    public sqrGUI(String image_file){
        super(new ImageIcon(image_file));
        setName(image_file);
        movable = false;
        resetXY();
    }
    
    public sqrGUI(String image_file, boolean mov){
        super(new ImageIcon(image_file));
        setName(image_file);
        movable = mov;
        resetXY();
    }
    
    /**
     * O Constractor autos theti tis idiotites tou Piece kai to vazi stin arhiki thesi.
     * @param iFile To onoma tou arhiou to Piece ( eg. BKing.png )
     * @param mov I ikanotita kinisis tou Piece.
     * @param c To hroma pou tha ehi to Piece.
     */
    public sqrGUI(String iFile, boolean mov, char c){
        this(iFile,mov);
        color = c;
        movable = mov;
        resetXY();
    }
    /**
     * Accessor.
     * Kani reset tin arhiki thesi tou Piece. Dld tis idies me autes pou theti o Constractor Piece().
     */
    public void resetXY(){
        pos.x = -1;
        pos.y = -1;
    }
    
    /**
     * Accessor.
     * @param iFile TO onoma tou arhiou pou tha ehi to Piece.
     */
    public void setPieceImage(String iFile){
        setIcon(new ImageIcon(iFile));
        setName(iFile);
    }
    
    /**
     * Accessor.
     * @param mov Theti tin ikanotita tou Piece na ine kinisimo i ohi apo to mouse.
     */
    public void setMovability(boolean mov){ movable = mov; }
    
    /**
     * Accessor.
     *  Theti to hroma tou Piece.
     * @param c Ine to hroma pou tha ehi to Piece.
     */
    public void setPieceColor(char c){ color = c; }
    
    public boolean getIfMovable(){ return movable; }
    
    /**
     * 
     * @return To hroma pou ehi to Piece.
     */
    public char getPieceColor(){return color; }
    
    /**
     * 
     * @return To X tis disdiastatis sindetagmenis tou Piece.
     */
    public int getXlocation(){ return pos.x; }
    /**
     * 
     * @return To Y tis disdiastatis sindetagmenis tou Piece.
     */
    public int getYlocation(){ return pos.y; }
    
    /**
     * Accessor
     * Theti tis X/Y sindetagmenis pou ine ta sinthetika tou onomatos.
     */
    public void locatePieceXY(){
        String temp = getParent().getName(); //An temp=04 tote to Location ine [0,4]
        pos.x = new Integer(temp.charAt(0));
        pos.y = new Integer(temp.charAt(1));
    }
}